package cn.tedu.charging.role.contoller;

import cn.tedu.charging.common.pojo.response.JsonResult;

import cn.tedu.charging.common.pojo.param.RoleQuery;
import cn.tedu.charging.role.pojo.param.RoleSaveParam;
import cn.tedu.charging.common.pojo.po.RoleStaff;
import cn.tedu.charging.common.pojo.vo.RoleVO;
import cn.tedu.charging.role.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/role")
@Slf4j
@Api(tags = "角色管理")
public class RoleController {
    @Autowired
    RoleService roleService;
    @ApiOperation("查询角色接口")
    @PostMapping("select")
    public JsonResult selectRole(@RequestBody RoleQuery roleQuery) {
        log.debug("查询角色接口的入参为{}",roleQuery);
        log.debug("查询角色接口调用业务层的入参为{}",roleQuery);
        List<RoleVO> list = roleService.selectRole(roleQuery);
        JsonResult jsonResult = JsonResult.ok(list, "成功查询到角色");
        log.debug("查询角色接口调用业务层的入参为{}出参为{}",roleQuery,jsonResult);
        return jsonResult;
    }
    @ApiOperation("保存角色接口")
    @PostMapping("save")
    public JsonResult saveRole(@RequestBody RoleSaveParam roleSaveParam) {
        log.debug("保存角色接口的入参为{}",roleSaveParam);
        log.debug("保存角色接口调用业务层的入参为{}",roleSaveParam);
        roleService.saveRole(roleSaveParam);
        JsonResult jsonResult = JsonResult.ok("成功保存角色");
        log.debug("保存角色接口调用业务层的入参为{}出参{}",roleSaveParam,jsonResult);
        return jsonResult;
    }
    @ApiOperation("删除角色接口")
    @PostMapping("delete/{roleId}")
    public JsonResult deleteRole(@PathVariable Long roleId) {
        log.debug("删除角色接口的入参为{}",roleId);
        log.debug("删除角色接口调用业务层的入参为{}",roleId);
        roleService.deleteRole(roleId);
        JsonResult jsonResult = JsonResult.ok("成功删除角色");
        log.debug("删除角色接口调用业务层的入参为{}出参{}",roleId,jsonResult);
        return jsonResult;
    }
    @ApiOperation("查询角色员工关联接口")
    @PostMapping("selectRoleStaff")
    public JsonResult selectRoleStaff(@RequestBody RoleStaff roleStaff) {
        log.debug("查询角色员工关联接口的入参为{}",roleStaff);
        log.debug("查询角色员工关联接口调用业务层的入参为{}",roleStaff);
        List<RoleStaff> list = roleService.selectRoleStaff(roleStaff);
        JsonResult jsonResult = JsonResult.ok(list, "查询roleStaff成功");
        log.debug("查询角色员工关联接口调用业务层的入参为{}出参为{}",roleStaff,jsonResult);
        return jsonResult;
    }
    @ApiOperation("删除角色员工关联接口")
    @PostMapping("deleteRoleStaff/{roleId}/{staffId}")
    public JsonResult deleteRolePerm(@PathVariable Long roleId,@PathVariable Long staffId) {
        log.debug("删除员工角色关联接口的入参为角色Id{}员工Id{}",roleId,staffId);
        log.debug("删除员工角色关联接口调用业务层的入参为角色Id{}员工Id{}",roleId,staffId);
        roleService.deleteRoleStaff(roleId,staffId);
        JsonResult jsonResult = JsonResult.ok("成功删除角色员工关联");
        log.debug("删除员工角色关联接口调用业务层的入参为角色Id{}员工Id{}出参{}",roleId,staffId,jsonResult);
        return jsonResult;
    }
    @ApiOperation("添加角色员工关联接口")
    @PostMapping("addRoleStaff/{roleId}/{staffId}")
    public JsonResult addRoleStaff(@PathVariable Long roleId,@PathVariable Long staffId) {
        log.debug("添加角色员工关联接口的入参为角色Id{}员工Id{}",roleId,staffId);
        log.debug("添加角色员工关联接口调用业务层的入参为角色Id{}员工Id{}",roleId,staffId);
        roleService.addRoleStaff(roleId,staffId);
        JsonResult jsonResult = JsonResult.ok("成功添加角色员工关联");
        log.debug("添加角色员工关联接口调用业务层的入参为角色Id{}员工Id{}出参{}",roleId,staffId,jsonResult);
        return jsonResult;
    }
    @ApiOperation("修改角色状态")
    @PostMapping("update/status/{roleId}/{status}")
    public JsonResult updateStatus(@PathVariable Long roleId,@PathVariable String status) {
        log.debug("修改角色状态接口入参为{}{}",roleId,status);
        log.debug("修改角色状态接口调用业务层的入参为{}{}",roleId,status);
        roleService.updateStatus(roleId,status);
        JsonResult jsonResult = JsonResult.ok("成功修改角色");
        log.debug("修改角色状态接口调用业务层的入参为{}{}出参{}",roleId,status,jsonResult);
        return jsonResult;
    }
    @ApiOperation("查询此员工未绑定的角色接口")
    @PostMapping("selectUnBindRole/{staffId}")
    public JsonResult selectUnBindRole(@PathVariable Long staffId) {
        log.debug("查询此员工未绑定的角色接口的入参为{}",staffId);
        log.debug("查询此员工未绑定的角色接口调用业务层的入参为{}",staffId);
        List<RoleVO> list = roleService.selectUnBindPerm(staffId);
        JsonResult jsonResult = JsonResult.ok(list,"成功修改用户状态");
        log.debug("查询此员工未绑定的角色接口调用业务层的入参为{}出参为{}",staffId,jsonResult);
        return jsonResult;
    }
}
